﻿using System;
using VideoStore.Domain.DAL;
using VideoStore.Domain.Entities;

namespace VideoStore.Business
{
    public class DeliveryBusinessObject
    {
        #region Fields

        private readonly IDeliveryDataAccess deliveryDao;

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="DeliveryBusinessObject"/> class.
        /// </summary>
        public DeliveryBusinessObject()
        {
            deliveryDao = new DeliveryDataAccess();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CatalogueBusinessObject"/> class.
        /// </summary>
        /// <param name="dao">The DAO.</param>
        public DeliveryBusinessObject(IDeliveryDataAccess dao)
        {
            // This constructor enables easy TDD as it takes whatever IDeliveryDataAccess implementation.
            deliveryDao = dao;
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Gets the delivery by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Delivery GetDeliveryById(Guid id)
        {
            Delivery delivery;
            try
            {
                delivery = deliveryDao.GetDeliveryById(id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return delivery;
        }

        /// <summary>
        /// Creates the delivery.
        /// </summary>
        /// <param name="newDelivery">The new delivery.</param>
        /// <returns></returns>
        public Delivery CreateDelivery(Delivery newDelivery)
        {
            Delivery delivery;
            try
            {
                delivery = deliveryDao.CreateDelivery(newDelivery);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return delivery;
        }

        #endregion
    }
}
